<?php
$this->pageTitle = 'Zoznam osôb';
?>
<div class="listing">
	<h3>Zoznam osôb</h3>
	<div class="top_links">
		<?php
		$allTypesTitle = 'Všetky typy';
		if (isset($actualType)) {
			echo $this->Html->link($allTypesTitle, array('controller' => 'person', 'action' => 'index'));
		} else {
			echo '<strong>' . $allTypesTitle . '</strong>';
		}

		foreach ($personTypes as $personType) {
			echo '<span> | </span>';
			$typeTitle = $personType['PersonType']['title'];
			if (isset($actualType) && $actualType == $typeTitle) {
				echo '<strong>' . $typeTitle . '</strong>';
			} else {
				echo $this->Html->link($typeTitle, array('controller' => 'person', 'action' => 'index', $personType['PersonType']['title']));
			}
		}
		?>
	</div>
	<table class="list">
		<thead>
			<tr>
				<th class="identifier"><?php echo $this->Paginator->sort('id', 'ID');?></th>
				<th class="col50"><?php echo $this->Paginator->sort('name', 'Meno');?></th>
				<th class="col50"><?php echo $this->Paginator->sort('surname', 'Priezvisko');?></th>
				<th class="col150"><?php echo $this->Paginator->sort('email', 'E-mail');?></th>
				<th class="col150"><?php echo $this->Paginator->sort('phone', 'Telefónne číslo');?></th>
				<th><?php echo $this->Paginator->sort('fk_parent_person_id', 'Nadriadený');?></th>
				<th class="col50"><?php echo $this->Paginator->sort('fk_person_type_id', 'Typ osoby');?></th>
				<th class="action"><?php echo 'Akcie'; ?></th>
			</tr>
		</thead>
		<tbody>
			<?php
			foreach ($persons as $person):
			?>
			<tr>
				<td class="number">
					<?php echo $person['Person']['id']; ?>
				</td>
				<td>
					<?php echo htmlspecialchars($person['Person']['name']); ?>
				</td>
				<td>
					<?php echo htmlspecialchars($person['Person']['surname']); ?>
				</td>
				<td>
					<?php echo htmlspecialchars($person['Person']['email']); ?>
				</td>
				<td>
					<?php echo htmlspecialchars($person['Person']['phone']); ?>
				</td>
				<td>
					<?php
						if ($person['Parent']['id']) {
							echo $this->Html->link(htmlspecialchars($person['Parent']['full_name']), array('action' => 'view', $person['Parent']['id']));
						}
					?>
				</td>
				<td>
					<?php
						if ($person['PersonType']['id']) {
							echo htmlspecialchars($person['PersonType']['title']);
						}
					?>
				</td>
				<td>
					<?php
						if (isset($userPermissions['person']['view'])) {
							echo $this->Html->link(__('View', true), array('action' => 'view', $person['Person']['id']), array('class' => 'show'));
						}
					?>
					<?php
						if (isset($userPermissions['person']['edit'])) {
							echo $this->Html->link(__('Uprav', true), array('action' => 'edit', $person['Person']['id']), array('class' => 'edit'));
						}
					?>
					<?php
						if (isset($userPermissions['person']['delete'])) {
							echo $this->Html->link(__('Delete', true), array('action' => 'delete', $person['Person']['id']), array('class' => 'delete'), __('Ste si istý, že chcete odstrániť záznam?', true));
						}
					?>
				</td>
			</tr>
			<?php endforeach; ?>
		</tbody>
	</table>

	<?php if ($this->Paginator->hasPage(2)): ?>
		<div class="pager">
			<?php echo $this->Paginator->prev('<< '.__('predchádzajúca', true), array(), null, array('class'=>'disabled')); ?>
			<?php echo $this->Paginator->numbers(); ?>
			<?php echo $this->Paginator->next(__('ďalšia', true).' >>', array(), null, array('class' => 'disabled')); ?>
		</div>
	<?php endif; ?>
</div>